<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/15 0015
 * Time: 19:19
 */

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Repositories\Admin\CategoryRepository;

class CategoryController extends Controller
{
    protected $categoryRepository;
    public function __construct(CategoryRepository $categoryRepository)
    {
        $this->categoryRepository = $categoryRepository;
    }
    /**
     * 获取所有分组
     */
    public function index()
    {
        $categorys = $this->categoryRepository->getAll();
        if($categorys)
            return json_encode(['code'=>200,'categorys'=>$categorys]);
        else
            return json_encode(['code'=>400,'msg'=>'获取分组信息出错']);
    }
    /**
     * 用户获取 分组列表
     */
    public function userGetCategory(){
        $categorys = $this->categoryRepository->getOrderByTypeAndStatus();
        if($categorys)
            return json_encode(['code'=>200,'categorys'=>$categorys]);
        else
            return json_encode(['code'=>400,'msg'=>'获取分组信息出错']);
    }
}